﻿@{
    ViewBag.Title = "Register";
    Layout = "~/Views/Shared/_LayoutPageAll.cshtml";
}
@*页面中心内容*@

<div class="content clearfix">
    @*局部导航*@
    <div class="breadcrumbs">
        <h2 class="element-invisible">You are here</h2><div class="breadcrumb"><a href="/">返回首页</a>» 用户账号注册</div>
    </div>
    @*标签页*@
    <div id="content" class="column content-inner">
        <div class="section">
            <h1 class="title" id="page-title">User account</h1>
            <h2 class="element-invisible">Primary tabs</h2>
            <ul class="tabs primary">
                <li class="active"><a href="/Register/Register" class="active">新建账号<span class="element-invisible">(active tab)</span></a></li>
                <li><a href="/Login/Usert">登录</a></li>

            </ul>
        </div>
        @*注册块*@
        <div class="region region-content">
            <div id="block-system-main" class="block block-system">
                <div class="content">
                    <form class="user-info-from-cookie" enctype="multipart/form-data" action="注册.html" method="post" id="user-register-form" accept-charset="UTF-8">
                        <div>
                            <div id="edit-account" class="form-wrapper">
                                <div class="form-item form-type-textfield form-item-name">
                                    <label for="edit-name">用户名 <span class="form-required" title="This field is required.">*</span></label>
                                    <input class="username form-text required" type="text" id="Uname" name="name" placeholder="请输入真实姓名,方便我们核实" size="60" maxlength="60" onblur="YtxtName()" /><span id="a1"></span>

                                </div>
                                <div class="form-item form-type-textfield form-item-mail">
                                    <label for="edit-mail">地址 <span class="form-required" title="This field is required.">*</span></label>
                                    <input type="text" id="Uaddr" name="Uaddr" placeholder="请输入地址" size="60" maxlength="254" class="form-text required" onblur="Ytxtaddr()" /><span id="a2"></span>

                                </div>
                                <div class="form-item form-type-textfield form-item-mail">
                                    <label for="edit-mail">手机号码 <span class="form-required" onblur="YtxtPhone()" title=" this field is required.">*</span></label>
                                    <input type="text" id="Utel" name="Utel" placeholder="请输入手机号码" size="60" maxlength="254" class="form-text required" onblur="YtxtTel()" /><span id="a3"></span>

                                </div>
                                <div class="form-item form-type-textfield form-item-mail">
                                    <label for="edit-mail">短信验证码 <span class="form-required" title="This field is required.">*</span></label>

                                    <div><input type="text" id="yan" name="yan" placeholder="请输入验证码" size="60" maxlength="100" class="form-text required" onblur="Ytxtyan()" /><input id="Button1" type="button" value="点击获取验证码" onclick="settime(this)" /><span id="a4"></span></div>
                                </div>
                                <div class="form-item form-type-textfield form-item-mail">
                                    <label for="edit-mail">密码 <span class="form-required" title="This field is required.">*</span></label>
                                    <input type="password" id="Upwd" name="Upwd" placeholder="密码由6-20位字母，数字和符号组合" size="60" maxlength="254" class="form-text required" onblur="Ytxtpwd()" /><span id="a5"></span>
                                </div>
                                <div class="form-item form-type-textfield form-item-mail">
                                    <label for="edit-mail">确认密码 <span class="form-required" title="This field is required.">*</span></label>
                                    <input type="password" id="Upwdr" name="Upwdr" placeholder="密码由6-20位字母，数字和符号组合" size="60" maxlength="254" class="form-text required" onblur="Ytxtpwdr()" /><span id="a6"></span>
                                </div>




                                <input type="hidden" name="timezone" value="Asia/Bangkok" />
                            </div><input type="hidden" name="form_build_id" value="form-j3mwM1q78HNc06ksNWA3jfMwWQyyKV0wTCYKQQPBLs4" />
                            <input type="hidden" name="form_id" value="user_register_form" />
                            <div class="form-actions form-wrapper" id="edit-actions"><input type="button" id="edit-submit" name="op" value="注册" class="form-submit" onclick="fun()" /></div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>

<script src="~/js/jquery-1.8.2.js"></script>
<script>
 ///点击获取验证码
    ///点击获取验证码
    var countdown = 60;
    function settime(obj) {
        var Utel = $("#Utel").val();
        if (countdown == 60)
        {
            $.ajax({
                url: "/Register/sendmes",
                type: "post",
                data: {
                    tel: Utel,
                },

            })
        }
        if (countdown == 0) {
            obj.removeAttribute("disabled");
            obj.value = "免费获取验证码";
            countdown = 60;
            return;
        } else {
            obj.setAttribute("disabled", true);
            obj.value = "重新发送(" + countdown + ")";
            countdown--;
           
        }
        setTimeout(function () {
            settime(obj)
        }
            , 1000)

    }
    function YtxtName() {
        var Uname = $("#Uname").val();
        ///用户名
        if (Uname == "") {
            $("#a1").html("用户名不能为空！");
            $("#a1").css("color", "red");
            return;

        }

        else {

            $("#a1").html("");
        }
    }
    function Ytxtaddr() {
        var Uaddr = $("#Uaddr").val();
        ///地址
        if (Uaddr == "") {
            $("#a2").html("地址不能为空！");
            $("#a2").css("color", "red");
            return;

        }

        else {

            $("#a2").html("");

        }
    }
    function  YtxtTel(){
        var Utel = $("#Utel").val();
        var reg = /^1[34578]\d{9}$/;
        ///电话
        if (Utel == "") {
            $("#a3").html("电话不能为空！");
            $("#a3").css("color", "red");
            return;

        }
        else if (!reg.test(Utel)) {
            $("#a3").html("手机号格式不正确！");
            $("#a3").css("color", "red");
            return;
        }

        else {

            $("#a3").html("");

        }
    }

    ///验证码
    function Ytxtyan() {
        var yan = $("#yan").val();


        if (yan == "") {
            $("#a4").html("验证码不能为空！");
            $("#a4").css("color", "red");
            return;

        }

        else {

            $("#a4").html("");

        }
    }
    function Ytxtpwd() {
        var Upwd = $("#Upwd").val();

        var reg1 = /^[a-zA-Z\d_]{6,}$/
        ///密码
        if (Upwd == "") {
            $("#a5").html("密码不能为空！");
            $("#a5").css("color", "red");
            return;

        }
        else if (!reg1.test(Upwd)) {
            $("#a5").html("密码格式最少为6位！");
            $("#a5").css("color", "red");
            return;
        }

        else {

            $("#a5").html("");

        }
    }
    function Ytxtpwdr() {
        var Upwdr = $("#Upwdr").val();
        var Upwd = $("#Upwd").val();
        ///确认密码
        if (Upwdr == "") {
            $("#a6").html("确认密码不能为空！");
            $("#a6").css("color", "red");
            return;

        }
        else if (Upwdr!= Upwd) {
            $("#a6").html("两次密码不一致！");
            $("#a6").css("color", "red");
        }

        else {

            $("#a6").html("");

        }
    }


        function fun() {
            var Uname = $("#Uname").val();
            var Uaddr = $("#Uaddr").val();
            var Utel = $("#Utel").val();
            var yan = $("#yan").val();
            var Upwd = $("#Upwd").val();
            var Upwdr = $("#Upwdr").val();
            var account = $("#Utel").val();
            ///用户名
            if (Uname == "") {
                $("#a1").html("用户名不能为空！");
                $("#a1").css("color", "red");
                return;

            }

            else {

                $("#a1").html("");

            }
            ///地址
            if (Uaddr == "") {
                $("#a2").html("地址不能为空！");
                $("#a2").css("color", "red");
                return;

            }

            else {

                $("#a2").html("");

            }
            ///电话
            var reg = /^1[34578]\d{9}$/;

            if (Utel == "") {
                $("#a3").html("电话不能为空！");
                $("#a3").css("color", "red");
                return;

            }
            else if (!reg.test(Utel)) {
                $("#a3").html("手机号格式不正确！");
                $("#a3").css("color", "red");
                return;
            }

            else {

                $("#a3").html("");

            }
            ///验证码
            if (yan == "") {
                $("#a4").html("验证码不能为空！");
                $("#a4").css("color", "red");
                return;

            }

            else {

                $("#a4").html("");

            }
            var reg1 = /^[a-zA-Z\d_]{6,}$/
            ///密码
            if (Upwd == "") {
                $("#a5").html("密码不能为空！");
                $("#a5").css("color", "red");
                return;

            }
            else if (!reg1.test(Upwd)) {
                $("#a5").html("密码格式最少为6位！");
                $("#a5").css("color", "red");
                return;
            }

            else {

                $("#a5").html("");

            }
            ///确认密码
            if (Upwdr == "") {
                $("#a6").html("确认密码不能为空！");
                $("#a6").css("color", "red");
                return;

            }
            else if (Upwdr!= Upwd)
            {
                $("#a6").html("两次密码不一致！");
                $("#a6").css("color", "red");
            }

            else {

                $("#a6").html("");

            }

            $.ajax({
                url: "/Register/VerifyMes",
                type: "post",
                data: {
                    code: $("#yan").val()
                },
                success: function (data) {
                    if (data == 0) {
                        alert('验证码错误！')
                        return;
                    } else {





                    }
                }
            })
            $.ajax({

                url: "http://localhost:19451/api/Home/GetRegin",
                type: "Get",
                data: {
                    account: account,
                    pwd: Upwd,
                    name: Uname,
                    addr: Uaddr,
                    tel: Utel,


                },
                success: function (data) {
                    if (data == 1) {
                        alert('注册成功！')
                        location.href = "/Login/Usert"
                        return;
                    }
                    else if (data == 2) {
                        alert('号码已存在！')
                        return;
                    }
                    else {
                        alert('注册失败！')
                        return;
                    }
                }


            })


    }

</script>

